﻿using System;
using System.Collections.Generic;
using System.Linq;
using SuppKids.Licensing.LicenseManager.Resources;

namespace SuppKids.Licensing.LicenseManager.Extensions
{
    public static class EnumExtensions
    {
        private const string enumTemplate = "{0}_{1}";

        public static string GetLocalizedEnumValue(this object value)
        {
            string result = null;

            if (value != null)
            {
                var enumType = value.GetType();

                if (!(value is Enum))
                {
                    return value.ToString();
                }

                result = General.ResourceManager.GetString(string.Format(enumTemplate, enumType.Name, Enum.GetName(enumType, value))) ?? value.ToString();
            }

            return result;
        }

        public static IEnumerable<T> GetPossibleEnumValues<T>()
        {
            return Enum.GetValues(typeof (T)).Cast<T>();
        }
    }
}